package com.huahua.component;

import com.huahua.annotation.Authority;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * 权限处理器
 *
 * @author huahua
 */
@Component
public class AuthorityBeanPostProcess implements BeanPostProcessor {
    public static Map<String,Authority> map = new HashMap();
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        Class<?> aClass = bean.getClass();
        Method[] declaredMethods = aClass.getDeclaredMethods();
        for (Method method : declaredMethods) {
            if (method.isAnnotationPresent(Authority.class)) {
                String name = method.getName();
                Authority annotation = method.getAnnotation(Authority.class);
                map.put(name,annotation);
            }
        }
        return bean;
    }
}